package edu.rit.drh4818.file;


import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;

import javax.swing.*;
import javax.vecmath.Color3f;

import edu.rit.drh4818.volume.*;


/**
 * 
 * Frame to display volume renderer, using the fire data sets.
 * 
 * @author Darren Headrick
 *
 */
@SuppressWarnings("serial")
public class FileRenderer extends JPanel
{
	/**
	 * Initialize frame. Settings default to first in each list.
	 */
	public FileRenderer( String filename ) 
	{
		super( new BorderLayout() );
		
		Volume v = FileData.loadFromFile( new File( filename ) );
		v.setColormap(new GreyscaleColormap());
		v.setup();
		
		VolumeCanvas volRend = new VolumeCanvas( v, 0, 1.5F, new Color3f( new Color( .5F,.5F,.5F) )); 
		volRend.setSize(600, 600);
		add( volRend );
	}

	
	
	/**
	 * Open a new frame with a volume renderer.
	 * @param args
	 */
	public static void main(String[] args) 
	{	
		if( args.length != 1 ) 
		{
			System.out.println( "Error must pass filename as argument" );
			return;
		}
		
		long totalMem = Runtime.getRuntime().totalMemory();
		if( totalMem < 500000 ) 
			System.out.println(  "Warning, heap space might not be large enough: " + totalMem + "." );

		JFrame frame = new JFrame("Java3D Volume Rendering " + args[0] );
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setContentPane( new FileRenderer(args[0]) );
		frame.pack();
		frame.setVisible( true );
	}
	
}
